package com.sx.gongzhong.pest;

import com.sx.gongzhong.model.HeadParamBean;
import com.sx.gongzhong.model.LocationBean;
import com.sx.gongzhong.model.ReplyUserBean;
import com.sx.gongzhong.net.ApiManager;
import com.sx.gongzhong.net.BaseCallBack;
import com.sx.gongzhong.view.IVoidView;

import java.util.List;
import java.util.Map;

/**
 * Created by XZY on 2018/1/9.
 * 全民护路新增
 */

public class DefendRoadAddPest {

    private IVoidView voidView;

    public DefendRoadAddPest(IVoidView voidView) {
        this.voidView = voidView;
    }

    /**
     *
     * @param locationBean 地址对象
     * @param content 内容
     * @param files 文件集合
     */
    public void addDefendRoad(LocationBean locationBean,String content
                ,List<String> files){
        Map<String,Object> map= HeadParamBean.getHead();
        if (locationBean!=null){
            map.put("address",locationBean.getAddress());
            map.put("lat",locationBean.getLat());
            map.put("lon",locationBean.getLon());
        }
        map.put("content",content);
        if (files!=null){
            String strs="";
            int count=files.size();
            for (int i=0;i<count;i++){
                if (i==count-1){
                    strs=strs+files.get(i);
                }else {
                    strs=strs+files.get(i)+",";
                }
            }
            map.put("fileIds",strs);
        }
        new ApiManager().addDefendRoad(map, new BaseCallBack<ReplyUserBean.BaseResult<Void>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Void> response) {
                voidView.voidView("新增成功");
            }

            @Override
            public void onFailures(String message) {
                voidView.showError(message);
            }
        });

    }
}
